import '../../public.dart';

class HistoryListItem {
  // 卖卡记录列表项
  static Widget sellRecord(
    SellRecordPageResponseDto record,
    BuildContext context,
  ) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: Colors.grey.withValues(alpha: 0.1),
            spreadRadius: 1,
            blurRadius: 3,
            offset: const Offset(0, 1),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 标题和金额
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                record.cardType ?? '',
                style: const TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                ),
              ),
              Text(
                '₦ ${record.cashValue?.toStringAsFixed(0) ?? '0'}',
                style: const TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ],
          ),
          const SizedBox(height: 8),
          // 卡类型
          Text(
            '${record.cardCategory} ${record.cardAmount ?? ''}',
            style: TextStyle(fontSize: 14, color: Colors.grey[600]),
          ),
          const SizedBox(height: 8),
          // 订单号和复制图标
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                'Order Number: ${record.orderNum}',
                style: TextStyle(fontSize: 14, color: Colors.grey[600]),
              ),
              IconButton(
                onPressed: () {
                  // 复制订单号
                  Clipboard.setData(ClipboardData(text: record.orderNum ?? ''));
                  // 提示复制成功
                  BrnToast.show('Order number copied', context);
                },
                icon: const Icon(Icons.copy, size: 18, color: Colors.grey),
              ),
            ],
          ),
          const SizedBox(height: 8),
          // 时间和状态
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                record.createTime ?? '',
                style: TextStyle(fontSize: 14, color: Colors.grey[500]),
              ),
              Container(
                padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
                decoration: BoxDecoration(
                  color: getStatusColor(record.status),
                  borderRadius: BorderRadius.circular(12),
                ),
                child: Text(
                  getStatusText(record.status),
                  style: const TextStyle(fontSize: 12, color: Colors.white),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  // 提现记录列表项
  static Widget withdrawRecord(
    WithdrawRecordPageResponseDto record,
    BuildContext context,
  ) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8),
        boxShadow: [
          BoxShadow(
            color: Colors.grey.withValues(alpha: 0.1),
            spreadRadius: 1,
            blurRadius: 3,
            offset: const Offset(0, 1),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 银行名称和金额
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                record.bankCardType ?? '',
                style: const TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                ),
              ),
              Text(
                '₦ ${record.withdrawAmount?.toStringAsFixed(0) ?? '0'}',
                style: const TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ],
          ),
          const SizedBox(height: 8),
          // 银行账户
          Text(
            CryptoUtil.decryptData(record.bankCard) ?? '',
            style: TextStyle(fontSize: 14, color: Colors.grey[600]),
          ),
          const SizedBox(height: 8),
          // 订单号和复制图标
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                'Order Number: ${record.orderNum}',
                style: TextStyle(fontSize: 14, color: Colors.grey[600]),
              ),
              IconButton(
                onPressed: () {
                  // 复制订单号
                  Clipboard.setData(ClipboardData(text: record.orderNum ?? ''));
                  // 提示复制成功
                  BrnToast.show('Order number copied', context);
                },
                icon: const Icon(Icons.copy, size: 18, color: Colors.grey),
              ),
            ],
          ),
          const SizedBox(height: 8),
          // 时间和状态
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                record.createTime ?? '',
                style: TextStyle(fontSize: 14, color: Colors.grey[500]),
              ),
              Container(
                padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
                decoration: BoxDecoration(
                  color: getStatusColor(record.status),
                  borderRadius: BorderRadius.circular(12),
                ),
                child: Text(
                  getStatusText(record.status),
                  style: const TextStyle(fontSize: 12, color: Colors.white),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  // 获取状态颜色
  static Color getStatusColor(int? status) {
    switch (status) {
      case 2:
        return Colors.orange;
      case 1:
        return Colors.green;
      case 0:
        return Colors.red;
      default:
        return Colors.grey;
    }
  }

  // 获取状态文本
  static String getStatusText(int? status) {
    switch (status) {
      case 2:
        return 'Pending';
      case 1:
        return 'Successful';
      case 0:
        return 'Rejected';
      default:
        return 'Unknown';
    }
  }
}
